package org.example.commons.repository;

import org.example.commons.entity.SysRole;
import org.example.commons.entity.SysUserRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * author 陈伯瑞
 * date 2020/6/16 0016 18:55
 * version 1.0
 **/
@Repository
public interface SysUserRoleRepository extends JpaRepository<SysUserRole, Long> {
    @Query("select r from SysUserRole sur " +
            "left join SysRole r on sur.roleId = r.roleId " +
            "where sur.adminId = :adminId ")
    List<SysRole> findRoleByAdminId(Long adminId);

    @Query("select r.roleId from SysUserRole sur " +
            "left join SysRole r on sur.roleId = r.roleId " +
            "where sur.adminId = :adminId ")
    List<Long> findRoleIdByAdminId(Long adminId);

    void deleteByRoleId(Long roleId);
}
